﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace RaygunDiplomacy.Graphics
{
   public delegate void ResourceHandler<TResource>(ref TResource resource) where TResource : SlimDX.Direct3D9.Resource;

   public class DelegateGraphicsResource<TResource> : IGraphicsResource
      where TResource : SlimDX.Direct3D9.Resource
   {
      TResource resource;

      ResourceHandler<TResource> reset;
      ResourceHandler<TResource> release;
      ResourceHandler<TResource> dispose;

      public TResource Resource
      {
         get { return resource; }
      }

      public DelegateGraphicsResource(
         ResourceHandler<TResource> reset,
         ResourceHandler<TResource> release,
         ResourceHandler<TResource> dispose)
      {
         this.reset = reset;
         this.release = release;
         this.dispose = dispose;
      }

      public void Reset()
      {
         if (reset != null)
         {
            reset(ref resource);
         }
      }

      public void Release()
      {
         if (release != null)
         {
            release(ref resource);
         }
      }

      public void Dispose()
      {
         if (dispose != null)
         {
            dispose(ref resource);
         }
      }
   }
}
